package com.breeze.mvxdemo.mvc;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.breeze.mvxdemo.R;
import com.breeze.mvxdemo.bean.Account;
import com.breeze.mvxdemo.callbacks.AccountCallback;

public class MVCActivity extends AppCompatActivity {

    private EditText mUserNameET;
    private TextView mResultTV;
    private MVCModel mMVCModel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mvp);
        initView();
        mMVCModel = new MVCModel();
    }

    private void initView() {
        mUserNameET = findViewById(R.id.userName);
        mResultTV = findViewById(R.id.result);
    }

    public void submit(View view) {
        String name = mUserNameET.getText().toString();
        mMVCModel.getAccountData(name, new AccountCallback() {
            @Override
            public void onSuccess(Account account) {
                showSuccessPage(account);
            }

            @Override
            public void onFailed() {
                showFailedPage();
            }
        });
    }

    private void showSuccessPage(Account account) {
        mResultTV.setText("用户账号：" + account.name + " | " + "用户等级：" + account.level);
    }

    private void showFailedPage() {
        mResultTV.setText("获取数据失败");
    }

}